package com.jinqing.wuchuang.RedisMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisAuthUserMapper {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 将验证码的uuid存入redis，15分钟过期
     * @param code
     */
    public void insertCode(String code,String value){
        stringRedisTemplate.opsForValue().set(code,value);
        stringRedisTemplate.expire(code,15, TimeUnit.MINUTES);//设置过期时间
    }

    /**
     * 前端在登陆时发送验证码的code，通过redis查找，与预存的值对比
     * @param code
     * @return code对应验证码的值
     */
    public String getValueByCode(String code){

        return stringRedisTemplate.opsForValue().get(code);
    }

}
